/*
 * This file is part of aion-engine <aion-engine.net>
 *
 * aion-engine is private software: you can redistribute it and or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Private Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with aion-engine.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.network.aion.serverpackets;


import com.aionengine.gameserver.configs.main.GSConfig;
import com.aionengine.gameserver.configs.main.MembershipConfig;
import com.aionengine.gameserver.model.gameobjects.player.emotion.Emotion;
import com.aionengine.gameserver.network.aion.AionConnection;
import com.aionengine.gameserver.network.aion.AionServerPacket;

import java.util.Collection;

/**
 * 
 * @modify xXMashUpXx
 *
 */
public class SM_EMOTION_LIST extends AionServerPacket {

    byte action;
    Collection<Emotion> emotions;

    /**
     * @param action
     */
    public SM_EMOTION_LIST(byte action, Collection<Emotion> emotions) {
        this.action = action;
        this.emotions = emotions;
    }

    @Override
    protected void writeImpl(AionConnection con) {
        writeC(action);
        if (con.getActivePlayer().havePermission(MembershipConfig.EMOTIONS_ALL)) {
        	//TODO Ex funciones.
        	/**
        	 *             writeH(82);
            for (int i = 0; i < 82; i++) {
                writeH(64 + i);
                writeD(0x00);
            }
        	 */
        	boolean isKR = (GSConfig.SERVER_COUNTRY_CODE == 0);
			writeH(isKR ? 86 : 85);
			for (int i = 64; i <= (isKR ? 149 : 148); i++) {
				writeH(i);
				writeD(0x00);
			}
        } else if (emotions == null || emotions.isEmpty()) {
            writeH(0);
        } else {
            writeH(emotions.size());
            for (Emotion emotion : emotions) {
                writeH(emotion.getId());
                writeD(emotion.getRemainingTime());//remaining time
            }
        }
    }
}
